package com.jiaming.employee.common.utils;

import cn.hutool.crypto.asymmetric.AsymmetricAlgorithm;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;

/**
 * @author dragon
 * @create 2021-04-14 16:18
 */
public class SecureKeyUtil {

    public static final String PRIVATE_KEY = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAJqqZuXsnhC7DOlzXW3Su1ISKHYPnnGTcVLucCN2uVCutZRxDYafn6E5gBuD38bN/waWZdUJJpmq9SXIB5rA4kDgFctvNl//D8lWFeqscaN1mEXKnopPeLdAdOXFhgmP6NBSporKFa17ZkSErRRSgfzU4IJEPEdXC2B2Cey+EaOjAgMBAAECgYEAkNfqW4MXmHWEJxC6O4JxmO+WYtJHwPei1lakQCIMdInZVTX2w8+zT+qolZwPsn/ySHoKzdKvCpQ21vYYYQ4oE7qDqRLv1kzvqydDroPeoHf3b9bKQIZgPaTdWYJ+1bSL2q7940s645TNx8tOXYuG3tr4eoHbfzwygwvUkohip0ECQQD1sfPUw/hOTxAlFSvAwSXCVctEaXg1oxDxEf1EDfn8wfplO0nl8I3iJTh5Nnt5OkLTTHZ+GuAaSJlwWuyfOR6DAkEAoScPDAaYGugsUEDaHjNaYZgx8k8NEWbQzfuZ/oEGDgiWBeAzdbcFLij9bL6j/GlU1UexQHSpa8/KSWcUydJcYQJBAMhOelG+K1P8lVcGOZN+ZIBZXcy6h+yCsy820VqIYoS0yKV7frXeNm5mlfIMfwHIg+6safZJhucmxSGan0r4UG0CQFQppPcf3oJ27OXA6OlK4pIDvVoSJP4Il1ZsZ4F+et4LZ+aLr/RzcDYqXChV7CjgDdkRhyXlh7HxpHDvb/DzdyECQD+dt1yoMv75Oz7EpUPvzS9VRBTWHknyQp1jbsZHgzpavmwfcQLGTZYk6JeF3FCGEhSGjTK+0C34OpFxQeMnRD0=";
    public static final String PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCaqmbl7J4Quwzpc11t0rtSEih2D55xk3FS7nAjdrlQrrWUcQ2Gn5+hOYAbg9/Gzf8GlmXVCSaZqvUlyAeawOJA4BXLbzZf/w/JVhXqrHGjdZhFyp6KT3i3QHTlxYYJj+jQUqaKyhWte2ZEhK0UUoH81OCCRDxHVwtgdgnsvhGjowIDAQAB";

    public static String decrypt(String content) {
        RSA rsa = new RSA(AsymmetricAlgorithm.RSA_ECB_PKCS1.getValue(), PRIVATE_KEY, PUBLIC_KEY);
        // 使用工具解密
        return rsa.decryptStr(content, KeyType.PrivateKey);
    }

    public static void main(String[] args) {
        // 创建公钥私钥方法
        RSA newRsa = new RSA();
        // 获得私钥
        String privateKeyBase64 = newRsa.getPrivateKeyBase64();
        // 获得公钥
        String publicKeyBase64 = newRsa.getPublicKeyBase64();
        System.out.println(privateKeyBase64);
        System.out.println(publicKeyBase64);
    }
}
